package org.summer.lawyer.controller.wx;

import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.summer.common.core.domain.R;
import org.summer.common.mybatis.core.page.PageQuery;
import org.summer.common.mybatis.core.page.TableDataInfo;
import org.summer.lawyer.domain.vo.category.CategoryVo;
import org.summer.lawyer.domain.vo.spu.SpuDetailVo;
import org.summer.lawyer.service.ICategoryService;
import org.summer.lawyer.service.ISpuService;

/**
 *
 */
@Tag(name = "微信小程序服务信息相关接口", description = "微信小程序服务信息相关接口")
@SaIgnore
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/wx/spu")
public class WxSpuController {

    private final ICategoryService categoryService;

    private final ISpuService spuService;

    @Parameters({
            @Parameter(name = "parentId", description = "一级分类ID(1文书模版,2代写文书,2法律咨询,4法律顾问,5诉讼服务)")
    })
    @Operation(description = "获取服务分类列表")
    @GetMapping("/listCategory")
    public TableDataInfo<CategoryVo> list(CategoryVo vo){
        PageQuery pageQuery = new PageQuery();
        pageQuery.setPageSize(PageQuery.DEFAULT_PAGE_SIZE);
        pageQuery.setOrderByColumn("categorySort");
        return categoryService.selectPage(vo, pageQuery);
    }

    @Parameters({
            @Parameter(name = "categoryId", description = "服务分类ID"),
            @Parameter(name = "categoryName", description = "服务名称"),
            @Parameter(name = "categoryParentId", description = "一级分类ID(1文书模版,2代写文书,2法律咨询,4法律顾问,5诉讼服务)"),
            @Parameter(name = "spuName", description = "服务名称")
    })
    @Operation(description = "通过categoryParentId获取服务列表(返回全部）")
    @GetMapping("/list")
    public TableDataInfo<SpuDetailVo> list(SpuDetailVo vo, PageQuery pageQuery){
        pageQuery.setPageSize(PageQuery.DEFAULT_PAGE_SIZE);
        vo.setSpuStatus("1");
        return spuService.selectPageSpuDetailList(vo, pageQuery);
    }

    @Parameters({
            @Parameter(name = "spuId", description = "服务主键ID", in = ParameterIn.PATH, required = true)
    })
    @Operation(description = "获取服务详情")
    @GetMapping("/{spuId}")
    public R<SpuDetailVo> get(@PathVariable("spuId") Long spuId){
        return R.ok("", spuService.selectSpuDetailVoById(spuId));
    }


}
